<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['role']=$_SESSION['role'];
if($_RQ['op']=='main'){
	$member=cfc('core')->member_show($_SESSION['uid']);
	$mymember=pdo_get('jy_nongfee_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$member=array_merge($member,$mymember);
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$member['isbaonum']=pdo_count('core_credit_log',array('tag'=>'duibao','plugin'=>'jy_nongfee','type'=>1,'is_add'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$return['member']=$member;
	$balance=pdo_get('jy_nongfee_balance',array('status'=>0,'end_time >'=>time(),'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$balance['end_time']=$balance['end_time']?date('Y-m-d H:i',$balance['end_time']):'';
	$return['balance']=$balance;
	$bao_levelidtitle=$item=$this->getcolumn('teamlevel',array('id'=>$return['pluginset']['bao_levelid'],'uniacid'=>$_SESSION['uniacid']),'title');
	$return['pluginset']['bao_levelidtitle']=$bao_levelidtitle;
	$return['list']=array();
	set_html('title','我的释放值');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_nongfee_baolog',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($return['list'] as &$v){
			$cang=pdo_get('jy_nongfee_cang',array('id'=>$v['cangid'],'uniacid'=>$_SESSION['uniacid']));
			$cangtitle=$cang['title'];
			$yaopaixu=pdo_getcolumn('jy_nongfee_yao',array('id'=>$v['yaoid'],'uniacid'=>$_SESSION['uniacid']),'paixu');
			$v['title']=$cangtitle.'第'.$yaopaixu.'期';
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
	}
	exi($return);
}
if($_RQ['op']=='post'){
	$balance=pdo_get('jy_nongfee_balance',array('status'=>0,'end_time >'=>time(),'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$post=get_postdata();
	if(!$post['fee']){
		exi('请输入兑换'.$this->cd_title.'！','erroe');
	}
	if($balance['lastmoney']<$post['fee']){
		exi('兑换额度不能大于，当前剩余释放值额度！','error');
	}
	$item=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
	if($item['credit4']<$post['fee']){
		exi('当前剩余'.$this->cd_title.'只有'.$item['credit4'].'个！','error');
	}
	$sf_rate=$this->teamsetting['sf_rate']?:1;
	$credit3=$post['fee']/$sf_rate;
	model('core/member')->member_credit($_SESSION['uid'],'credit3',$credit3,true,'jy_nongfee',''.$this->cd_title.'兑换获得');
	model('core/member')->member_credit($_SESSION['uid'],'credit4',$post['fee'],false,'jy_nongfee',''.$this->cd_title.'兑换'.$this->cb_title);
	pdo_update('jy_nongfee_balance',array('lastmoney -='=>$post['fee']),array('id'=>$balance['id'],'uniacid'=>$_SESSION['uniacid']));
	exi('兑换成功！');
}